<?php
session_start ();
if (! isset ( $_SESSION ['yazi'] )) {
	header ( 'Refresh:2;url=/deng1.php' );
	die ( '<h3>你还未登录，请先登录</h3>' );
}

$user = $_SESSION ['yazi'];
@$id = $_REQUEST ['id'];
@$message = "";
if (! empty ( $id )) {
	@$initialPwd = $_REQUEST ['initialPwd'];
	@$login = $_REQUEST ['login'];
	@$newPassword = $_REQUEST ['newPassword'];
	@$confirmPassword = $_REQUEST ['confirmPassword'];
	$pdo = new PDO ( 'mysql:dbname=shu', 'root' );
	
	$s = $pdo->prepare ( 'select * from yazi where id=:id' );
	$s->execute ( array (
			'id' => $id 
	) );
	
	$a = $s->fetch ( PDO::FETCH_NAMED );
	if ($a ['password'] != $initialPwd) {
		$message = "原密码错误";
	} else {
		if ($newPassword != $confirmPassword) {
			$message = "两次输入的密码不一致";
		} else {
			$s = $pdo->prepare ( 'update yazi set login=:login,password=:newPassword where id=:id' );
			if ($s->execute ( array (
					'login' => $login,
					'id' => $user ['id'],
					'newPassword' => $newPassword 
			) )) {
				
				unset ( $a ['password'] );
				$_SESSION ['yazi'] = $a;
				$message = "修改成功";
				header ( 'Refresh:1;url=/tui1.php' );
			}
		}
	}
}

?>
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap 模板</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
	charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!--[if lt IE 9]>
         <script src="js/html5shiv.js"></script>
         <script src="js/respond.min.js"></script>
      <![endif]-->
</head>
<style>
.c {
	color: blue;
}
</style>
<body>
	<nav class="navbar navbar-default">
		<div class="container">
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed"
					data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
					<span class="sr-only">切换</span> <span class="icon-bar"></span> <span
						class="icon-bar"></span> <span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="/th4.php">点餐系统</a>
			</div>
			<div class="collapse navbar-collapse"
				id="bs-example-navbar-collapse-1">
				<ul class="nav navbar-nav">
					<li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">订单管理 <span class="caret"></span></a>
						<ul class="dropdown-menu">
							<li><a href="dinglie.php">订单列表</a></li>
							<li><a href="dingji.php">订单记录</a></li>
						</ul></li>
				</ul>
				<ul class="nav navbar-nav">
					<li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">菜品管理 <span class="caret"></span></a>
						<ul class="dropdown-menu">
							<li><a href="jcp.php">添加菜品</a></li>
							<li><a href="cpl.php">菜品列表</a></li>
							<li class="divider"></li>
							<li><a href="jcx.php">添加菜品类型</a></li>
							<li><a href="cplie.php">菜品类型列表</a></li>
						</ul></li>
				</ul>
				<ul class="nav navbar-nav">
					<li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">餐桌管理 <span class="caret"></span></a>
						<ul class="dropdown-menu">
							<li><a href="jiazhuo.php">添加餐桌</a></li>
							<li><a href="canzl.php">餐桌列表 </a></li>
						</ul></li>
				</ul>
				<ul class="nav navbar-nav">
					<li class="dropdown"><a href="#" class="dropdown-toggle"
						data-toggle="dropdown">登录管理 <span class="caret"></span></a>
						<ul class="dropdown-menu">
							<li><a href="#" data-toggle="modal" data-target="#aboutModal">关于点餐系统</a></li>
							<li><a href="xiugai.php">修改登录信息</a></li>
							<li><a href="#tui" data-toggle="modal">退出登录</a></li>
						</ul></li>
				</ul>
			</div>
		</div>
		<div class="modal fade" id="aboutModal" tabindex="-1">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">
							<span>&times;</span><span class="sr-only">Close</span>
						</button>
						<h4 class="modal-title">关于皇子大酒店点餐系统</h4>
					</div>
					<div class="modal-body">
						本皇子大酒店，精选优质渣料，<br> 选用上等地沟油，所有汤均用高级洗脚水熬制一天一夜而成。<br>
						各位顾客可放心点餐，我们还有优质的售后服务。<br> 我们保证在顾客吃后负责挖坑，免除顾客的后顾之忧。<br>
						最后，感谢各位顾客的光临，我们的酒店因你而生辉。

					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-warning" data-dismiss="modal">确定</button>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade" id="tui" tabindex="-1">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal">
							<span>&times;</span><span class="sr-only">Close</span>
						</button>
						<h4 class="modal-title">确定退出登录</h4>
					</div>
					<div class="modal-body">你确定要退出登录吗？</div>
					<div class="modal-footer">
						<a type="button" class="btn btn-default" href="tui.php">确定</a>
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					</div>
				</div>
			</div>
		</div>
	</nav>
	<div class="container">
		<div class="row">
			<div class="col-sm-3 col-md-2 page-left">
				<a class="btn btn-default btn-block" href="th4.php">返回主页</a>
			</div>
			<hr class="visible-xs-block">
			<div class="col-sm-6 col-md-5 col-lg-4">
			<?php if (! empty ( $message )) { ?>
					<div class="alert alert-danger"><?php echo $message;?> <a
						class="close" data-dismiss="alert">&times;</a>
				</div>
					<?php } ?>
				
				<div class="panel panel-primary">
					<div class="panel-heading">
						<h1 class="panel-title">
							<span class="glyphicon glyphicon-edit"></span> 修改登录信息
						</h1>
					</div>
					<div class="panel-body">
						<form action="xiugai.php" method="post" class="form-horizontal">
							<div class="form-group">
								<input type="hidden" name="id" value="<?php echo $user['id'];?>" />
								<label class="control-label col-sm-4 hidden-xs">原密码：</label>
								<div class="col-sm-8">
									<input name="initialPwd" type="password" class="form-control" placeholder="原密码">
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-sm-4 hidden-xs">新登录名：</label>
								<div class="col-sm-8">
									<input name="login" class="form-control" placeholder="新登录名">
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-sm-4 hidden-xs">新密码：</label>
								<div class="col-sm-8">
									<input name="newPassword" type="password" class="form-control" placeholder="密码">
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-sm-4 hidden-xs">确认密码：</label>
								<div class="col-sm-8">
									<input name="confirmPassword" type="password" class="form-control"
										placeholder="确认">
								</div>
							</div>
							<div class="row">
								<div class="col-sm-offset-4 col-sm-4">
									<button class="btn btn-primary btn-block" type="submit">修改</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>